<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>DataExtractor: E:/cas/cas.0.7.0/sfw/src/MinConsole/MinConsole.0.8.0/MinConsole/Gaf/Utils/INI/StreamIniDataParser.cs Source File</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<link href="../../doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.7.2 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul class="tablist">
      <li><a href="../../index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="../../namespaces.html"><span>Packages</span></a></li>
      <li><a href="../../annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="../../files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs2">
    <ul class="tablist">
      <li><a href="../../files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<h1>E:/cas/cas.0.7.0/sfw/src/MinConsole/MinConsole.0.8.0/MinConsole/Gaf/Utils/INI/StreamIniDataParser.cs</h1>  </div>
</div>
<div class="contents">
<a href="../../d3/d63/StreamIniDataParser_8cs.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="keyword">using</span> System;
<a name="l00002"></a>00002 <span class="keyword">using</span> System.IO;
<a name="l00003"></a>00003 <span class="keyword">using</span> System.Collections.Generic;
<a name="l00004"></a>00004 <span class="keyword">using</span> System.Text.RegularExpressions;
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 <span class="keyword">namespace </span>MinConsole.IniParser
<a name="l00007"></a>00007 {
<a name="l00011"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html">00011</a>     <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html" title="Represents an INI data parser for streams.">StreamIniDataParser</a>
<a name="l00012"></a>00012     {
<a name="l00013"></a>00013 <span class="preprocessor">        #region Default regular expression strings</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span>
<a name="l00015"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#aefb6dbe4d0ef11793f88d108f7b547ee">00015</a>         <span class="keyword">private</span> <span class="keyword">const</span> <span class="keywordtype">string</span> strCommentRegex = <span class="stringliteral">@&quot;.*&quot;</span>;
<a name="l00016"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#aee5108a042334fb433138d92aeda3f47">00016</a>         <span class="keyword">private</span> <span class="keyword">const</span> <span class="keywordtype">string</span> strSectionRegexStart = <span class="stringliteral">@&quot;^(\s*?)&quot;</span>;
<a name="l00017"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a8d1c361e66c392c2d0f3428a07878adf">00017</a>         <span class="keyword">private</span> <span class="keyword">const</span> <span class="keywordtype">string</span> strSectionRegexMiddle = <span class="stringliteral">@&quot;{1}\s*[_\.\-\w\d\s]+\s*&quot;</span>;
<a name="l00018"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a61c1b470bc8dccffbd68e9523843c21d">00018</a>         <span class="keyword">private</span> <span class="keyword">const</span> <span class="keywordtype">string</span> strSectionRegexEnd = <span class="stringliteral">@&quot;(\s*?)$&quot;</span>;
<a name="l00019"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a626df1bb8222fc40356d07e45d210a57">00019</a>         <span class="keyword">private</span> <span class="keyword">const</span> <span class="keywordtype">string</span> strKeyRegex = <span class="stringliteral">@&quot;^(\s*[_\.\d\w]*\s*)&quot;</span>;
<a name="l00020"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a0c6b407d4a0d5e4a3c5f79a9b5fb8e56">00020</a>         <span class="keyword">private</span> <span class="keyword">const</span> <span class="keywordtype">string</span> strValueRegex = <span class="stringliteral">@&quot;([\s\d\w\W]*)$&quot;</span>;
<a name="l00021"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a6dd9fd0d560c836830ede43aa4d782ee">00021</a>         <span class="keyword">private</span> <span class="keyword">const</span> <span class="keywordtype">string</span> strSpecialRegexChars = <span class="stringliteral">@&quot;[\^$.|?*+()&quot;</span>;
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 <span class="preprocessor">        #endregion</span>
<a name="l00024"></a>00024 <span class="preprocessor"></span>
<a name="l00025"></a>00025 <span class="preprocessor">        #region Public Methods</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span>
<a name="l00049"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a4b3dd1e774a65b0735f1af137d3b1db0">00049</a>         <span class="keyword">public</span> <a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html" title="Represents an INI data parser for streams.">StreamIniDataParser</a>()
<a name="l00050"></a>00050         {
<a name="l00051"></a>00051             <span class="comment">//Default delimiter values</span>
<a name="l00052"></a>00052             CommentDelimiter = <span class="charliteral">&#39;;&#39;</span>;
<a name="l00053"></a>00053             KeyValueDelimiter = <span class="charliteral">&#39;=&#39;</span>;
<a name="l00054"></a>00054             SectionDelimiters = <span class="keyword">new</span> <span class="keywordtype">char</span>[] { <span class="charliteral">&#39;[&#39;</span>, <span class="charliteral">&#39;]&#39;</span> };
<a name="l00055"></a>00055 
<a name="l00056"></a>00056             _currentTmpData = <span class="keyword">new</span> <a class="code" href="../../d4/dcc/classMinConsole_1_1IniParser_1_1SectionDataCollection.html" title="Represents a collection of SectionData.">SectionDataCollection</a>();
<a name="l00057"></a>00057         }
<a name="l00058"></a>00058 
<a name="l00064"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a2c8af07efea192ebb51356f9c8a9ec00">00064</a>         <span class="keyword">public</span> <a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html" title="Represents all data from an INI file.">IniData</a> ReadData(StreamReader reader)
<a name="l00065"></a>00065         {
<a name="l00066"></a>00066             <span class="keywordflow">return</span> ReadData(reader, <span class="keyword">false</span>);
<a name="l00067"></a>00067         }
<a name="l00068"></a>00068 
<a name="l00078"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#afc991f7cb012903ef53c3084231b6dbc">00078</a>         <span class="keyword">public</span> <a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html" title="Represents all data from an INI file.">IniData</a> ReadData(StreamReader reader, <span class="keywordtype">bool</span> relaxedIniFormat)
<a name="l00079"></a>00079         {
<a name="l00080"></a>00080             _relaxedIniFormat = relaxedIniFormat;
<a name="l00081"></a>00081 
<a name="l00082"></a>00082             <span class="keywordflow">if</span> (reader == null)
<a name="l00083"></a>00083                 <span class="keywordflow">throw</span> <span class="keyword">new</span> ArgumentNullException(<span class="stringliteral">&quot;reader&quot;</span>, <span class="stringliteral">&quot;The StreamReader object is null&quot;</span>);
<a name="l00084"></a>00084 
<a name="l00085"></a>00085             <span class="keywordflow">try</span>
<a name="l00086"></a>00086             {
<a name="l00087"></a>00087                 <span class="keywordflow">while</span> (!reader.EndOfStream)
<a name="l00088"></a>00088                     ProcessLine(reader.ReadLine());
<a name="l00089"></a>00089 
<a name="l00090"></a>00090                 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html" title="Represents all data from an INI file.">IniData</a>((<a class="code" href="../../d4/dcc/classMinConsole_1_1IniParser_1_1SectionDataCollection.html" title="Represents a collection of SectionData.">SectionDataCollection</a>)_currentTmpData.Clone());
<a name="l00091"></a>00091             }
<a name="l00092"></a>00092             <span class="keywordflow">catch</span> (Exception ex)
<a name="l00093"></a>00093             {
<a name="l00094"></a>00094                 _currentTmpData.Clear();
<a name="l00095"></a>00095                 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="../../d7/d3a/classMinConsole_1_1IniParser_1_1ParsingException.html" title="Represents an error ococcurred while parsing data.">ParsingException</a>(<span class="stringliteral">&quot;Parsing error: &quot;</span> + ex.Message, ex);
<a name="l00096"></a>00096             }
<a name="l00097"></a>00097             <span class="keywordflow">finally</span>
<a name="l00098"></a>00098             {
<a name="l00099"></a>00099                 _currentTmpData.Clear();
<a name="l00100"></a>00100             }
<a name="l00101"></a>00101         }
<a name="l00102"></a>00102 
<a name="l00108"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a50e3fe582a2eec871e6d45bd3cde2f3a">00108</a>         <span class="keyword">public</span> <span class="keywordtype">void</span> WriteData(StreamWriter writer, <a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html" title="Represents all data from an INI file.">IniData</a> iniData)
<a name="l00109"></a>00109         {
<a name="l00110"></a>00110 
<a name="l00111"></a>00111             <a class="code" href="../../d4/dcc/classMinConsole_1_1IniParser_1_1SectionDataCollection.html" title="Represents a collection of SectionData.">SectionDataCollection</a> sdc = iniData.<a class="code" href="../../dd/de3/classMinConsole_1_1IniParser_1_1IniData.html#a23b81f7bb2f67084758e5fb63f2431ad" title="Gets or sets all the SectionData for this IniData instance.">Sections</a>;
<a name="l00112"></a>00112 
<a name="l00113"></a>00113 
<a name="l00114"></a>00114             <span class="comment">//Write sections</span>
<a name="l00115"></a>00115             <span class="keywordflow">foreach</span> (<a class="code" href="../../da/d5e/classMinConsole_1_1IniParser_1_1SectionData.html" title="Information associated to a section in a INI FileIncludes both the value and the comments associated ...">SectionData</a> sd <span class="keywordflow">in</span> sdc)
<a name="l00116"></a>00116             {
<a name="l00117"></a>00117                 <span class="comment">//Write section comments</span>
<a name="l00118"></a>00118                 <span class="keywordflow">foreach</span> (<span class="keywordtype">string</span> sectionComment <span class="keywordflow">in</span> sd.<a class="code" href="../../da/d5e/classMinConsole_1_1IniParser_1_1SectionData.html#a1ea697b805ef5c5b697bfe83e6972f7d" title="Gets or sets the comment list associated to this section.">Comments</a>)
<a name="l00119"></a>00119                     writer.WriteLine(<span class="keywordtype">string</span>.Format(<span class="stringliteral">&quot;{0}{1}&quot;</span>, CommentDelimiter, sectionComment));
<a name="l00120"></a>00120 
<a name="l00121"></a>00121                 <span class="comment">//Write section name</span>
<a name="l00122"></a>00122                 writer.WriteLine(<span class="keywordtype">string</span>.Format(
<a name="l00123"></a>00123                     <span class="stringliteral">&quot;{0}{1}{2}&quot;</span>,
<a name="l00124"></a>00124                     SectionDelimiters[0], sd.<a class="code" href="../../da/d5e/classMinConsole_1_1IniParser_1_1SectionData.html#adab8fdbc92f03583cbd7bc609240d010" title="Gets or sets the name of the section.">SectionName</a>, SectionDelimiters[1]));
<a name="l00125"></a>00125 
<a name="l00126"></a>00126                 <span class="comment">//Write section keys</span>
<a name="l00127"></a>00127                 <span class="keywordflow">foreach</span> (<a class="code" href="../../d7/d40/classMinConsole_1_1IniParser_1_1KeyData.html" title="Information associated to a key from an INI file.Includes both the value and the comments associated ...">KeyData</a> kd <span class="keywordflow">in</span> sd.<a class="code" href="../../da/d5e/classMinConsole_1_1IniParser_1_1SectionData.html#a1b9719c87649991337673af8793d90ee" title="Gets or sets the keys associated to this section.">Keys</a>)
<a name="l00128"></a>00128                 {
<a name="l00129"></a>00129                     <span class="comment">//Write key comments</span>
<a name="l00130"></a>00130                     <span class="keywordflow">foreach</span> (<span class="keywordtype">string</span> keyComment <span class="keywordflow">in</span> kd.<a class="code" href="../../d7/d40/classMinConsole_1_1IniParser_1_1KeyData.html#a1ea697b805ef5c5b697bfe83e6972f7d" title="Gets or sets the comment list associated to this key.">Comments</a>)
<a name="l00131"></a>00131                         writer.WriteLine(<span class="keywordtype">string</span>.Format(<span class="stringliteral">&quot;{0}{1}&quot;</span>, CommentDelimiter, keyComment));
<a name="l00132"></a>00132 
<a name="l00133"></a>00133                     <span class="comment">//Write key and value</span>
<a name="l00134"></a>00134                     writer.WriteLine(<span class="keywordtype">string</span>.Format(
<a name="l00135"></a>00135                         <span class="stringliteral">&quot;{0} {1} {2}&quot;</span>,
<a name="l00136"></a>00136                         kd.<a class="code" href="../../d7/d40/classMinConsole_1_1IniParser_1_1KeyData.html#ad75286a69f558484322dac5297e2ed64" title="Gets or sets the name of the key.">KeyName</a>, KeyValueDelimiter, kd.<a class="code" href="../../d7/d40/classMinConsole_1_1IniParser_1_1KeyData.html#af7b88db799d8f791f785e437bc6099d2" title="Gets or sets the value associated to this key.">Value</a>));
<a name="l00137"></a>00137                 }
<a name="l00138"></a>00138 
<a name="l00139"></a>00139                 writer.WriteLine();     <span class="comment">//blank line</span>
<a name="l00140"></a>00140 
<a name="l00141"></a>00141             }
<a name="l00142"></a>00142         }
<a name="l00143"></a>00143 
<a name="l00144"></a>00144 <span class="preprocessor">        #endregion</span>
<a name="l00145"></a>00145 <span class="preprocessor"></span>
<a name="l00146"></a>00146 <span class="preprocessor">        #region Properties</span>
<a name="l00147"></a>00147 <span class="preprocessor"></span>
<a name="l00152"></a>00152         <span class="keyword">public</span> <span class="keywordtype">char</span> CommentDelimiter
<a name="l00153"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a1da4ac6b94c8a9a87d26abc935476080">00153</a>         {
<a name="l00154"></a>00154             <span class="keyword">get</span> { <span class="keywordflow">return</span> _commentDelimiter; }
<a name="l00155"></a>00155             <span class="keyword">set</span>
<a name="l00156"></a>00156             {
<a name="l00157"></a>00157                 _commentRegex = <span class="keyword">new</span> Regex(value + strCommentRegex);
<a name="l00158"></a>00158                 _commentDelimiter = value;
<a name="l00159"></a>00159             }
<a name="l00160"></a>00160         }
<a name="l00161"></a>00161 
<a name="l00166"></a>00166         <span class="keyword">public</span> <span class="keywordtype">char</span>[] SectionDelimiters
<a name="l00167"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a8f66bd3400eb43631c46be3da4594e32">00167</a>         {
<a name="l00168"></a>00168             <span class="keyword">get</span> { <span class="keywordflow">return</span> _sectionDelimiters; }
<a name="l00169"></a>00169             <span class="keyword">set</span>
<a name="l00170"></a>00170             {
<a name="l00171"></a>00171                 <span class="keywordflow">if</span> (value == null || value.Length != 2)
<a name="l00172"></a>00172                     <span class="keywordflow">return</span>;
<a name="l00173"></a>00173 
<a name="l00174"></a>00174                 <span class="keywordtype">string</span> tmp = strSectionRegexStart;
<a name="l00175"></a>00175                 <span class="keywordflow">if</span> (strSpecialRegexChars.Contains(<span class="keyword">new</span> <span class="keywordtype">string</span>(value[0], 1)))
<a name="l00176"></a>00176                     tmp += <span class="stringliteral">&quot;\\&quot;</span> + value[0];
<a name="l00177"></a>00177                 <span class="keywordflow">else</span> tmp += value[0];
<a name="l00178"></a>00178 
<a name="l00179"></a>00179                 tmp += strSectionRegexMiddle;
<a name="l00180"></a>00180 
<a name="l00181"></a>00181                 <span class="keywordflow">if</span> (strSpecialRegexChars.Contains(<span class="keyword">new</span> <span class="keywordtype">string</span>(value[1], 1)))
<a name="l00182"></a>00182                     tmp += <span class="stringliteral">&quot;\\&quot;</span> + value[1];
<a name="l00183"></a>00183                 <span class="keywordflow">else</span>
<a name="l00184"></a>00184                     tmp += value[1];
<a name="l00185"></a>00185 
<a name="l00186"></a>00186                 tmp += strSectionRegexEnd;
<a name="l00187"></a>00187 
<a name="l00188"></a>00188                 _sectionRegex = <span class="keyword">new</span> Regex(tmp);
<a name="l00189"></a>00189                 _sectionDelimiters = value;
<a name="l00190"></a>00190             }
<a name="l00191"></a>00191         }
<a name="l00192"></a>00192 
<a name="l00197"></a>00197         <span class="keyword">public</span> <span class="keywordtype">char</span> KeyValueDelimiter
<a name="l00198"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#aaec6e5b59136d0f9be39975ca7f4a8b0">00198</a>         {
<a name="l00199"></a>00199             <span class="keyword">get</span> { <span class="keywordflow">return</span> _keyValueDelimiter; }
<a name="l00200"></a>00200             <span class="keyword">set</span>
<a name="l00201"></a>00201             {
<a name="l00202"></a>00202                 _keyValuePairRegex = <span class="keyword">new</span> Regex(strKeyRegex + value + strValueRegex);
<a name="l00203"></a>00203                 _keyValueDelimiter = value;
<a name="l00204"></a>00204             }
<a name="l00205"></a>00205         }
<a name="l00206"></a>00206 
<a name="l00212"></a>00212         <span class="keyword">public</span> <span class="keywordtype">string</span> CommentRegexString
<a name="l00213"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#aa0938f1ddbaac9c20c5fdad1690d7744">00213</a>         {
<a name="l00214"></a>00214             <span class="keyword">get</span>
<a name="l00215"></a>00215             {
<a name="l00216"></a>00216                 <span class="keywordflow">if</span> (_commentRegex == null)
<a name="l00217"></a>00217                     <span class="keywordflow">return</span> <span class="keywordtype">string</span>.Empty;
<a name="l00218"></a>00218 
<a name="l00219"></a>00219                 <span class="keywordflow">return</span> _commentRegex.ToString();
<a name="l00220"></a>00220             }
<a name="l00221"></a>00221         }
<a name="l00222"></a>00222 
<a name="l00228"></a>00228         <span class="keyword">public</span> <span class="keywordtype">string</span> SectionRegexString
<a name="l00229"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a4b6f9dd95c54c036cc944dd97395c001">00229</a>         {
<a name="l00230"></a>00230             <span class="keyword">get</span>
<a name="l00231"></a>00231             {
<a name="l00232"></a>00232                 <span class="keywordflow">if</span> (_sectionRegex == null)
<a name="l00233"></a>00233                     <span class="keywordflow">return</span> <span class="keywordtype">string</span>.Empty;
<a name="l00234"></a>00234 
<a name="l00235"></a>00235                 <span class="keywordflow">return</span> _sectionRegex.ToString();
<a name="l00236"></a>00236             }
<a name="l00237"></a>00237         }
<a name="l00238"></a>00238 
<a name="l00244"></a>00244         <span class="keyword">public</span> <span class="keywordtype">string</span> KeyValuePairRegexString
<a name="l00245"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#ad42d78ccf1521f3e0ab8020b9526af06">00245</a>         {
<a name="l00246"></a>00246             <span class="keyword">get</span>
<a name="l00247"></a>00247             {
<a name="l00248"></a>00248                 <span class="keywordflow">if</span> (_keyValuePairRegex == null)
<a name="l00249"></a>00249                     <span class="keywordflow">return</span> <span class="keywordtype">string</span>.Empty;
<a name="l00250"></a>00250                 <span class="keywordflow">return</span> _keyValuePairRegex.ToString();
<a name="l00251"></a>00251             }
<a name="l00252"></a>00252         }
<a name="l00253"></a>00253 
<a name="l00254"></a>00254 <span class="preprocessor">        #endregion</span>
<a name="l00255"></a>00255 <span class="preprocessor"></span>
<a name="l00256"></a>00256 <span class="preprocessor">        #region Non-public methods</span>
<a name="l00257"></a>00257 <span class="preprocessor"></span>
<a name="l00265"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#adeac7d923c5f0b3921011010674efd37">00265</a>         <span class="keyword">private</span> <span class="keywordtype">bool</span> MatchComment(<span class="keywordtype">string</span> s)
<a name="l00266"></a>00266         {
<a name="l00267"></a>00267             <span class="keywordflow">if</span> (<span class="keywordtype">string</span>.IsNullOrEmpty(s))
<a name="l00268"></a>00268                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00269"></a>00269 
<a name="l00270"></a>00270             <span class="keywordflow">return</span> _commentRegex.Match(s).Success;
<a name="l00271"></a>00271         }
<a name="l00272"></a>00272 
<a name="l00280"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a597746e563f76233467e38247598f48b">00280</a>         <span class="keyword">private</span> <span class="keywordtype">bool</span> MatchSection(<span class="keywordtype">string</span> s)
<a name="l00281"></a>00281         {
<a name="l00282"></a>00282             <span class="keywordflow">if</span> (<span class="keywordtype">string</span>.IsNullOrEmpty(s))
<a name="l00283"></a>00283                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00284"></a>00284 
<a name="l00285"></a>00285             <span class="keywordflow">return</span> _sectionRegex.Match(s).Success;
<a name="l00286"></a>00286         }
<a name="l00287"></a>00287 
<a name="l00295"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a470f333e643e524c0a3e8a29f3efe020">00295</a>         <span class="keyword">private</span> <span class="keywordtype">bool</span> MatchKeyValuePair(<span class="keywordtype">string</span> s)
<a name="l00296"></a>00296         {
<a name="l00297"></a>00297             <span class="keywordflow">if</span> (<span class="keywordtype">string</span>.IsNullOrEmpty(s))
<a name="l00298"></a>00298                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00299"></a>00299 
<a name="l00300"></a>00300             <span class="keywordflow">return</span> _keyValuePairRegex.Match(s).Success;
<a name="l00301"></a>00301         }
<a name="l00302"></a>00302 
<a name="l00309"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a02c9a26b37d167c904c22d27f738c74c">00309</a>         <span class="keyword">private</span> <span class="keywordtype">string</span> ExtractComment(<span class="keywordtype">string</span> s)
<a name="l00310"></a>00310         {
<a name="l00311"></a>00311             <span class="keywordtype">string</span> tmp = _commentRegex.Match(s).Value.Trim();
<a name="l00312"></a>00312 
<a name="l00313"></a>00313             _currentCommentList.Add(tmp.Substring(1, tmp.Length - 1));
<a name="l00314"></a>00314 
<a name="l00315"></a>00315             <span class="keywordflow">return</span> s.Replace(tmp, <span class="stringliteral">&quot;&quot;</span>).Trim();
<a name="l00316"></a>00316         }
<a name="l00317"></a>00317 
<a name="l00322"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a184d416a63263e19f8a5319f86e47c38">00322</a>         <span class="keyword">private</span> <span class="keywordtype">void</span> ProcessLine(<span class="keywordtype">string</span> currentLine)
<a name="l00323"></a>00323         {
<a name="l00324"></a>00324 
<a name="l00325"></a>00325             currentLine = currentLine.Trim();
<a name="l00326"></a>00326             
<a name="l00327"></a>00327 <span class="preprocessor">            #region DebugIniFileLine</span>
<a name="l00328"></a>00328 <span class="preprocessor"></span>
<a name="l00329"></a>00329             <span class="comment">//if (currentLine.Equals(@&quot;LogDir = E:\cas\sfw\bin\MinConsole\MinConsole\bin\Release&quot;) == true)</span>
<a name="l00330"></a>00330             <span class="comment">//{</span>
<a name="l00331"></a>00331             <span class="comment">//    Console.WriteLine(&quot;PRESS A KEY TO continue !!!&quot;);</span>
<a name="l00332"></a>00332             <span class="comment">//    Console.ReadKey();</span>
<a name="l00333"></a>00333 
<a name="l00334"></a>00334             <span class="comment">//} //eof if</span>
<a name="l00335"></a>00335             
<a name="l00336"></a>00336 <span class="preprocessor">            #endregion DebugIniFileLine</span>
<a name="l00337"></a>00337 <span class="preprocessor"></span>
<a name="l00338"></a>00338 
<a name="l00339"></a>00339             <span class="comment">//Extract comments</span>
<a name="l00340"></a>00340             <span class="keywordflow">if</span> (MatchComment(currentLine))
<a name="l00341"></a>00341                 currentLine = ExtractComment(currentLine);
<a name="l00342"></a>00342 
<a name="l00343"></a>00343             <span class="comment">//Ignore empty lines</span>
<a name="l00344"></a>00344             <span class="keywordflow">if</span> (currentLine == String.Empty)
<a name="l00345"></a>00345                 <span class="keywordflow">return</span>;
<a name="l00346"></a>00346 
<a name="l00347"></a>00347             <span class="comment">//Process sections</span>
<a name="l00348"></a>00348             <span class="keywordflow">if</span> (MatchSection(currentLine))
<a name="l00349"></a>00349             {
<a name="l00350"></a>00350                 ProcessSection(currentLine);
<a name="l00351"></a>00351                 <span class="keywordflow">return</span>;
<a name="l00352"></a>00352             }
<a name="l00353"></a>00353 
<a name="l00354"></a>00354             <span class="comment">//Process keys</span>
<a name="l00355"></a>00355             <span class="keywordflow">if</span> (MatchKeyValuePair(currentLine))
<a name="l00356"></a>00356             {
<a name="l00357"></a>00357                 ProcessKeyValuePair(currentLine);
<a name="l00358"></a>00358                 <span class="keywordflow">return</span>;
<a name="l00359"></a>00359             }
<a name="l00360"></a>00360 
<a name="l00361"></a>00361             <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="../../d7/d3a/classMinConsole_1_1IniParser_1_1ParsingException.html" title="Represents an error ococcurred while parsing data.">ParsingException</a>(
<a name="l00362"></a>00362                 <span class="stringliteral">&quot;Couldn&#39;t parse string: &quot;</span> + currentLine + <span class="stringliteral">&quot;. Unknown file format.&quot;</span>);
<a name="l00363"></a>00363         }
<a name="l00364"></a>00364 
<a name="l00369"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#af07efc40b0c5b6f4b6de8db653fd93fc">00369</a>         <span class="keyword">private</span> <span class="keywordtype">void</span> ProcessSection(<span class="keywordtype">string</span> s)
<a name="l00370"></a>00370         {
<a name="l00371"></a>00371             ProcessingSection = <span class="keyword">true</span>;
<a name="l00372"></a>00372 
<a name="l00373"></a>00373             <span class="keywordtype">string</span> tmp = _sectionRegex.Match(s).Value.Trim();
<a name="l00374"></a>00374 
<a name="l00375"></a>00375             <span class="comment">//Check bad string</span>
<a name="l00376"></a>00376             <span class="keywordflow">if</span> (tmp == <span class="keywordtype">string</span>.Empty)
<a name="l00377"></a>00377                 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="../../d7/d3a/classMinConsole_1_1IniParser_1_1ParsingException.html" title="Represents an error ococcurred while parsing data.">ParsingException</a>(<span class="stringliteral">&quot;Error parsing section. String: \&quot;&quot;</span> + s + <span class="stringliteral">&quot;\&quot;&quot;</span>);
<a name="l00378"></a>00378 
<a name="l00379"></a>00379             <span class="comment">//Remove section delimiters</span>
<a name="l00380"></a>00380             tmp = tmp.Substring(1, tmp.Length - 2).Trim();
<a name="l00381"></a>00381 
<a name="l00382"></a>00382             <span class="comment">//Checks correct ini format</span>
<a name="l00383"></a>00383             <span class="keywordflow">if</span> (_currentTmpData.ContainsSection(tmp))
<a name="l00384"></a>00384             {
<a name="l00385"></a>00385                 <span class="keywordflow">if</span> (_relaxedIniFormat)
<a name="l00386"></a>00386                 {
<a name="l00387"></a>00387                     ProcessingSection = <span class="keyword">false</span>;
<a name="l00388"></a>00388                     <span class="keywordflow">return</span>;
<a name="l00389"></a>00389                 }
<a name="l00390"></a>00390 
<a name="l00391"></a>00391                 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="../../d7/d3a/classMinConsole_1_1IniParser_1_1ParsingException.html" title="Represents an error ococcurred while parsing data.">ParsingException</a>(<span class="keywordtype">string</span>.Format(
<a name="l00392"></a>00392                     <span class="stringliteral">&quot;Error parsing section: Another section with the name [{0}] exists!&quot;</span>, s));
<a name="l00393"></a>00393             }
<a name="l00394"></a>00394 
<a name="l00395"></a>00395 
<a name="l00396"></a>00396             _currentSectionName = tmp;
<a name="l00397"></a>00397 
<a name="l00398"></a>00398             <span class="comment">//Add new section &amp; comments</span>
<a name="l00399"></a>00399             _currentTmpData.AddSection(tmp);
<a name="l00400"></a>00400             _currentTmpData.GetSectionData(tmp).Comments = _currentCommentList;
<a name="l00401"></a>00401             _currentCommentList.Clear();
<a name="l00402"></a>00402 
<a name="l00403"></a>00403 
<a name="l00404"></a>00404         }
<a name="l00405"></a>00405 
<a name="l00406"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a4a28acc9ee9529c3d0b362af508f1433">00406</a>         <span class="keyword">private</span> <span class="keywordtype">bool</span> <a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a4a28acc9ee9529c3d0b362af508f1433">_processingSecion</a>;
<a name="l00407"></a>00407         <span class="keyword">private</span> <span class="keywordtype">bool</span> ProcessingSection
<a name="l00408"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a1c4799bca7294d99cc0ba2cfbe29e27d">00408</a>         {
<a name="l00409"></a>00409             <span class="keyword">get</span> { <span class="keywordflow">return</span> _processingSecion; }
<a name="l00410"></a>00410             <span class="keyword">set</span> { _processingSecion = value; }
<a name="l00411"></a>00411         }
<a name="l00412"></a>00412 
<a name="l00417"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#ae48999a2223f0927b177b83b8ebba59e">00417</a>         <span class="keyword">private</span> <span class="keywordtype">void</span> ProcessKeyValuePair(<span class="keywordtype">string</span> s)
<a name="l00418"></a>00418         {
<a name="l00419"></a>00419             <span class="keywordflow">if</span> (!ProcessingSection)
<a name="l00420"></a>00420                 <span class="keywordflow">return</span>;
<a name="l00421"></a>00421 
<a name="l00422"></a>00422             <span class="keywordflow">if</span> (_currentSectionName == <span class="keywordtype">string</span>.Empty)
<a name="l00423"></a>00423                 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="../../d7/d3a/classMinConsole_1_1IniParser_1_1ParsingException.html" title="Represents an error ococcurred while parsing data.">ParsingException</a>(
<a name="l00424"></a>00424                     <span class="stringliteral">&quot;Bad file format: key doesn&#39;t match any section. String :&quot;</span> + s);
<a name="l00425"></a>00425             <span class="keywordtype">string</span> key = ExtractKey(s);
<a name="l00426"></a>00426             <span class="comment">//debug</span>
<a name="l00427"></a>00427 
<a name="l00428"></a>00428 <span class="preprocessor">            #region DebugKey</span>
<a name="l00429"></a>00429 <span class="preprocessor"></span>
<a name="l00430"></a>00430             <span class="comment">//if (key.Equals(&quot;ConnectionStringTemplate&quot;) == true)</span>
<a name="l00431"></a>00431             <span class="comment">//{</span>
<a name="l00432"></a>00432             <span class="comment">//    Console.WriteLine(&quot;Press key to continue&quot;);</span>
<a name="l00433"></a>00433             <span class="comment">//    Console.ReadKey();</span>
<a name="l00434"></a>00434             <span class="comment">//    Console.WriteLine(&quot;GOTCHA !!!&quot;);</span>
<a name="l00435"></a>00435             <span class="comment">//}</span>
<a name="l00436"></a>00436 <span class="preprocessor">            #endregion DebugKey</span>
<a name="l00437"></a>00437 <span class="preprocessor"></span>
<a name="l00438"></a>00438 
<a name="l00439"></a>00439             <span class="keywordtype">string</span> value = ExtractValue(s);
<a name="l00440"></a>00440 
<a name="l00441"></a>00441 
<a name="l00442"></a>00442             <span class="comment">//Checks correct ini format</span>
<a name="l00443"></a>00443             <span class="keywordflow">if</span> (_currentTmpData.GetSectionData(_currentSectionName).Keys.ContainsKey(key))
<a name="l00444"></a>00444             {
<a name="l00445"></a>00445                 <span class="keywordflow">if</span> (_relaxedIniFormat)
<a name="l00446"></a>00446                 {
<a name="l00447"></a>00447                     <span class="keywordflow">return</span>;
<a name="l00448"></a>00448                 }
<a name="l00449"></a>00449 
<a name="l00450"></a>00450                 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="../../d7/d3a/classMinConsole_1_1IniParser_1_1ParsingException.html" title="Represents an error ococcurred while parsing data.">ParsingException</a>(<span class="keywordtype">string</span>.Format(
<a name="l00451"></a>00451                                                    <span class="stringliteral">&quot;Error parsing section: Another key with the same name [{0}] already exists in section&quot;</span>,
<a name="l00452"></a>00452                                                    _currentSectionName));
<a name="l00453"></a>00453             }
<a name="l00454"></a>00454 
<a name="l00455"></a>00455             _currentTmpData.GetSectionData(_currentSectionName).Keys.AddKey(key);
<a name="l00456"></a>00456             _currentTmpData.GetSectionData(_currentSectionName).Keys.GetKeyData(key).Value = value;
<a name="l00457"></a>00457             _currentTmpData.GetSectionData(_currentSectionName).Keys.GetKeyData(key).Comments = _currentCommentList;
<a name="l00458"></a>00458             _currentCommentList.Clear();
<a name="l00459"></a>00459 
<a name="l00460"></a>00460         }
<a name="l00461"></a>00461 
<a name="l00467"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a72ba93dc134d61fe38275ef7324cf26d">00467</a>         <span class="keyword">private</span> <span class="keywordtype">string</span> ExtractKey(<span class="keywordtype">string</span> s)
<a name="l00468"></a>00468         {
<a name="l00469"></a>00469             <span class="keywordtype">string</span> tmp = _keyValuePairRegex.Match(s).Value;
<a name="l00470"></a>00470             <span class="keywordflow">if</span> (tmp == <span class="keywordtype">string</span>.Empty)
<a name="l00471"></a>00471                 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="../../d7/d3a/classMinConsole_1_1IniParser_1_1ParsingException.html" title="Represents an error ococcurred while parsing data.">ParsingException</a>(<span class="stringliteral">&quot;Error extracting key. String: \&quot;&quot;</span> + s + <span class="stringliteral">&quot;\&quot;&quot;</span>);
<a name="l00472"></a>00472 
<a name="l00473"></a>00473             <span class="keywordtype">int</span> index = tmp.IndexOf(_keyValueDelimiter, 0);
<a name="l00474"></a>00474 
<a name="l00475"></a>00475             <span class="keywordflow">return</span> tmp.Substring(0, index).Trim();
<a name="l00476"></a>00476         }
<a name="l00477"></a>00477 
<a name="l00483"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a4aaeec669403928a0c66c919f24d553c">00483</a>         <span class="keyword">private</span> <span class="keywordtype">string</span> ExtractValue(<span class="keywordtype">string</span> s)
<a name="l00484"></a>00484         {
<a name="l00485"></a>00485             <span class="keywordtype">string</span> tmp = _keyValuePairRegex.Match(s).Value.Trim();
<a name="l00486"></a>00486             <span class="keywordflow">if</span> (tmp == <span class="keywordtype">string</span>.Empty)
<a name="l00487"></a>00487                 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="../../d7/d3a/classMinConsole_1_1IniParser_1_1ParsingException.html" title="Represents an error ococcurred while parsing data.">ParsingException</a>(<span class="stringliteral">&quot;Error extracting value. String: \&quot;&quot;</span> + s + <span class="stringliteral">&quot;\&quot;&quot;</span>);
<a name="l00488"></a>00488 
<a name="l00489"></a>00489             <span class="keywordtype">int</span> index = tmp.IndexOf(_keyValueDelimiter, 0);
<a name="l00490"></a>00490 
<a name="l00491"></a>00491             <span class="keywordflow">return</span> tmp.Substring(index + 1, tmp.Length - index - 1).Trim();
<a name="l00492"></a>00492         }
<a name="l00493"></a>00493 
<a name="l00494"></a>00494 <span class="preprocessor">        #endregion</span>
<a name="l00495"></a>00495 <span class="preprocessor"></span>
<a name="l00496"></a>00496 <span class="preprocessor">        #region Non-public members</span>
<a name="l00497"></a>00497 <span class="preprocessor"></span>
<a name="l00501"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#ada9d5a9325079e721bc9e112b346e28c">00501</a>         <span class="keyword">private</span> readonly List&lt;string&gt; _currentCommentList = <span class="keyword">new</span> List&lt;string&gt;();
<a name="l00502"></a>00502 
<a name="l00506"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#aaa7844b9035c032b0cbce6105cf5ee0c">00506</a>         <span class="keyword">private</span> <span class="keywordtype">string</span> <a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#aaa7844b9035c032b0cbce6105cf5ee0c" title="Tmp var with the name of the seccion which is being process.">_currentSectionName</a>;
<a name="l00507"></a>00507 
<a name="l00511"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a8d6c54a7846ceb2fac0e9668f1ce03f7">00511</a>         <span class="keyword">private</span> readonly <a class="code" href="../../d4/dcc/classMinConsole_1_1IniParser_1_1SectionDataCollection.html" title="Represents a collection of SectionData.">SectionDataCollection</a> <a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a8d6c54a7846ceb2fac0e9668f1ce03f7" title="Temporary data for the parsing.">_currentTmpData</a>;
<a name="l00512"></a>00512 
<a name="l00516"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a45983e0f9b6a036dcc0614de2e43bf81">00516</a>         <span class="keyword">private</span> <span class="keywordtype">char</span> <a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a45983e0f9b6a036dcc0614de2e43bf81" title="Defines the character used as comment delimiter.">_commentDelimiter</a>;
<a name="l00517"></a>00517 
<a name="l00521"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a1111a370c67d78b7fbc11574be479138">00521</a>         <span class="keyword">private</span> <span class="keywordtype">char</span>[] <a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a1111a370c67d78b7fbc11574be479138" title="Defines the two characters used as section delimiters.">_sectionDelimiters</a>;
<a name="l00522"></a>00522 
<a name="l00526"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a4892f1d4d00ea04a0fab9e5592b5c301">00526</a>         <span class="keyword">private</span> <span class="keywordtype">char</span> <a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a4892f1d4d00ea04a0fab9e5592b5c301" title="Defines the character used as a key value pair link.">_keyValueDelimiter</a>;
<a name="l00527"></a>00527 
<a name="l00531"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a4e14581a4b607555cb68f4f2ddd3c193">00531</a>         <span class="keyword">private</span> Regex <a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a4e14581a4b607555cb68f4f2ddd3c193" title="Regular expression for matching a comment string.">_commentRegex</a>;
<a name="l00532"></a>00532 
<a name="l00536"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a3ce1070782f5d00936c8bdd0b7b6b36e">00536</a>         <span class="keyword">private</span> Regex <a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a3ce1070782f5d00936c8bdd0b7b6b36e" title="Regular expression for matching a section string.">_sectionRegex</a>;
<a name="l00537"></a>00537 
<a name="l00541"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a53a8766520c048a1f222bbb14fda71cb">00541</a>         <span class="keyword">private</span> Regex <a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a53a8766520c048a1f222bbb14fda71cb" title="Regular expression for matching a key / value pair string.">_keyValuePairRegex</a>;
<a name="l00542"></a>00542 
<a name="l00546"></a><a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a449a4b1316b26f22d58c5231de7132e1">00546</a>         <span class="keyword">private</span> <span class="keywordtype">bool</span> <a class="code" href="../../d8/db4/classMinConsole_1_1IniParser_1_1StreamIniDataParser.html#a449a4b1316b26f22d58c5231de7132e1" title="True to allow loading an IniFile with non-unique section or key.">_relaxedIniFormat</a>;
<a name="l00547"></a>00547 
<a name="l00548"></a>00548 <span class="preprocessor">        #endregion</span>
<a name="l00549"></a>00549 <span class="preprocessor"></span>    }
<a name="l00550"></a>00550 
<a name="l00551"></a>00551 }
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Sat Jan 22 2011 22:24:47 for DataExtractor by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
